import java.sql.*;

public class connect
{
	public static Statement doConnect(String IP,int PORT,String TABLE,String user,String passwd)
	{
		String JDriver = "com.mysql.jdbc.Driver";// SQL数据库引擎
        String connectDB = "jdbc:mysql://"+IP+":"+PORT+"/"+TABLE;// 数据源
        try 
        {
             Class.forName(JDriver);// 加载数据库引擎，返回给定字符串名的类
         } 
        catch (ClassNotFoundException e) 
        {
        // e.printStackTrace();
             System.out.println("加载数据库引擎失败");
             System.exit(0);
         }
         System.out.println("数据库驱动成功");
         try 
         {
        	 String user1 = user;
             String password = passwd;
             Connection con = DriverManager.getConnection(connectDB, user1, password);// 连接数据库对象
             System.out.println("连接数据库成功");
             Statement stmt = con.createStatement();
             return stmt;
		 } 
         catch (SQLException e) 
         {
               e.printStackTrace();
               System.out.println("数据库连接错误");
               System.exit(0);
         }
		return null;		
	}
}